// const db = wx.cloud.database()      //获取数据库的引用
import { add } from "../../utils/db";
import { multiUpload } from "../../utils/upload"
Page({
  data: {
    realname: "",
    files: [],     //图片临时地址
  },
  //打开相册，选择图片
  handleSelect(e) {
    // console.log(e)
    let arr = e.detail.tempFilePaths    //本地临时地址
    let files = arr.map(item => {
      return { url: item }
    })
    this.setData({
      files
    })

  },
  //点击上传
  async handleUpload() {
    //显示提示框，防止重复提交
    wx.showLoading({
      title: '正在提交',
      mask: true
    })
    // 批量上传图片
    let image = await multiUpload(this.data.files).catch(err => console.log(err))
    //添加数据库
    // let res =await add("users",{realname:this.data.realname,image})
    // console.log(res)
    let res = await add({ collection: "users", data: { realname: this.data.realname, image } })
    
    //隐藏加载框
    wx.hideLoading()

  }

})